home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / javax / swing / JDesktopPane.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  8.6 KB  |  284 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)JDesktopPane.java    1.24 98/08/28
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package javax.swing;
  16.  
  17. import java.util.Vector;
  18. import javax.swing.plaf.*;
  19. import javax.accessibility.*;
  20.  
  21. import java.io.ObjectOutputStream;
  22. import java.io.ObjectInputStream;
  23. import java.io.IOException;
  24.  
  25. /**
  26.  * A container used to create a multiple-document interface or a virtual desktop. 
  27.  * You create JInternalFrame objects and add them to the JDesktopPane. 
  28.  * JDesktopPane extends JLayeredPane to manage the potentially overlapping internal frames. It also 
  29.  * maintains a reference to an instance of DesktopManager that is set by the UI 
  30.  * class for the current Look and Feel (L&F). 
  31.  * <p>
  32.  * This class is normally used as the parent of JInternalFrames to provide a
  33.  * pluggable DesktopManager object to the JInternalFrames. The installUI of the 
  34.  * L&F specific implementation is responsible for setting the desktopManager 
  35.  * variable appropriately. When the parent of a JInternalFrame is a JDesktopPane, 
  36.  * it should delegate most of its behavior to the desktopManager (closing, resizing,
  37.  * etc).
  38.  * <p>
  39.  * For the keyboard keys used by this component in the standard Look and
  40.  * Feel (L&F) renditions, see the
  41.  * <a href="doc-files/Key-Index.html#JDesktopPane">JDesktopPane</a> key assignments.
  42.  * <p>
  43.  * <strong>Warning:</strong>
  44.  * Serialized objects of this class will not be compatible with 
  45.  * future Swing releases.  The current serialization support is appropriate
  46.  * for short term storage or RMI between applications running the same
  47.  * version of Swing.  A future release of Swing will provide support for
  48.  * long term persistence.
  49.  *
  50.  * @see JInternalFrame
  51.  * @see JInternalFrame.JDesktopIcon
  52.  * @see DesktopManager
  53.  *
  54.  * @version 1.24 08/28/98
  55.  * @author David Kloba
  56.  */
  57. public class JDesktopPane extends JLayeredPane implements Accessible
  58. {
  59.     /**
  60.      * @see #getUIClassID
  61.      * @see #readObject
  62.      */
  63.     private static final String uiClassID = "DesktopPaneUI";
  64.  
  65.     DesktopManager desktopManager;
  66.  
  67.     /** 
  68.      * Creates a new JDesktopPane.
  69.      */
  70.     public JDesktopPane() {
  71.         updateUI();
  72.     }
  73.  
  74.     /**
  75.      * Returns the L&F object that renders this component.
  76.      *
  77.      * @return the DesktopPaneUI object that renders this component
  78.      */
  79.     public DesktopPaneUI getUI() {
  80.         return (DesktopPaneUI)ui;
  81.     }
  82.  
  83.     /**
  84.      * Sets the L&F object that renders this component.
  85.      *
  86.      * @param ui  the DesktopPaneUI L&F object
  87.      * @see UIDefaults#getUI
  88.      */
  89.     public void setUI(DesktopPaneUI ui) {
  90.         super.setUI(ui);
  91.     }
  92.  
  93.     /** 
  94.      * Returns the DesktopManger that handles desktop-specific UI actions.
  95.      *
  96.      * @param d the DesktopManager currently in use 
  97.      */
  98.     public DesktopManager getDesktopManager() {
  99.         return desktopManager;
  100.     }
  101.  
  102.     /**
  103.      * Sets the DesktopManger that will handle desktop-specific UI actions.
  104.      *
  105.      * @param d the DesktopManager to use 
  106.      */
  107.     public void setDesktopManager(DesktopManager d) {
  108.         desktopManager = d;
  109.     }
  110.  
  111.     /**
  112.      * Notification from the UIManager that the L&F has changed. 
  113.      * Replaces the current UI object with the latest version from the 
  114.      * UIManager.
  115.      *
  116.      * @see JComponent#updateUI
  117.      */
  118.     public void updateUI() {
  119.         setUI((DesktopPaneUI)UIManager.getUI(this));
  120.     }
  121.  
  122.  
  123.     /**
  124.      * Returns the name of the L&F class that renders this component.
  125.      *
  126.      * @return "DesktopPaneUI"
  127.      * @see JComponent#getUIClassID
  128.      * @see UIDefaults#getUI
  129.      */
  130.     public String getUIClassID() {
  131.         return uiClassID;
  132.     }
  133.  
  134.     /** 
  135.      * Returns all JInternalFrames currently displayed in the
  136.      * desktop. Returns iconified frames as well as expanded frames.
  137.      *
  138.      * @return an array of JInternalFrame objects
  139.      */
  140.     public JInternalFrame[] getAllFrames() {
  141.         int i, count;
  142.         JInternalFrame[] results;
  143.         Vector vResults = new Vector(10);
  144.         Object next, tmp;
  145.  
  146.         count = getComponentCount();
  147.         for(i = 0; i < count; i++) {
  148.             next = getComponent(i);
  149.             if(next instanceof JInternalFrame)
  150.                 vResults.addElement(next);
  151.             else if(next instanceof JInternalFrame.JDesktopIcon)  {
  152.                 tmp = ((JInternalFrame.JDesktopIcon)next).getInternalFrame();
  153.                 if(tmp != null)
  154.                     vResults.addElement(tmp);
  155.             }
  156.         }
  157.  
  158.         results = new JInternalFrame[vResults.size()];
  159.         vResults.copyInto(results);
  160.  
  161.         return results;
  162.     }
  163.  
  164.     /**
  165.      * Returns all JInternalFrames currently displayed in the
  166.      * specified layer of the desktop. Returns iconified frames as well
  167.      * expanded frames.
  168.      *
  169.      * @param layer  an int specifying the desktop layer
  170.      * @return an array of JInternalFrame objects
  171.      * @see JLayeredPane
  172.      */
  173.     public JInternalFrame[] getAllFramesInLayer(int layer) {
  174.         int i, count;
  175.         JInternalFrame[] results;
  176.         Vector vResults = new Vector(10);
  177.         Object next, tmp;
  178.  
  179.         count = getComponentCount();
  180.         for(i = 0; i < count; i++) {
  181.             next = getComponent(i);
  182.             if(next instanceof JInternalFrame)
  183.                 if(((JInternalFrame)next).getLayer() == layer)
  184.                     vResults.addElement(next);
  185.             else if(next instanceof JInternalFrame.JDesktopIcon)  {
  186.                 tmp = ((JInternalFrame.JDesktopIcon)next).getInternalFrame();
  187.                 if(tmp != null && ((JInternalFrame)tmp).getLayer() == layer)
  188.                     vResults.addElement(tmp);
  189.             }
  190.         }
  191.  
  192.         results = new JInternalFrame[vResults.size()];
  193.         vResults.copyInto(results);
  194.  
  195.         return results;
  196.     }
  197.  
  198.     /**
  199.      * Returns true to indicate that this component paints every pixel
  200.      * in its range. (In other words, it does not have a transparent
  201.      * background or foreground.)
  202.      *
  203.      * @return true
  204.      * @see JComponent#isOpaque
  205.      */
  206.     public boolean isOpaque() {
  207.         return true;
  208.     }
  209.  
  210.  
  211.     /** 
  212.      * See readObject() and writeObject() in JComponent for more 
  213.      * information about serialization in Swing.
  214.      */
  215.     private void writeObject(ObjectOutputStream s) throws IOException {
  216.         s.defaultWriteObject();
  217.     if ((ui != null) && (getUIClassID().equals(uiClassID))) {
  218.         ui.installUI(this);
  219.     }
  220.     }
  221.  
  222.  
  223.     /**
  224.      * Returns a string representation of this JDesktopPane. This method 
  225.      * is intended to be used only for debugging purposes, and the 
  226.      * content and format of the returned string may vary between      
  227.      * implementations. The returned string may be empty but may not 
  228.      * be <code>null</code>.
  229.      * <P>
  230.      * Overriding paramString() to provide information about the
  231.      * specific new aspects of the JFC components.
  232.      * 
  233.      * @return  a string representation of this JDesktopPane.
  234.      */
  235.     protected String paramString() {
  236.     String desktopManagerString = (desktopManager != null ?
  237.                        desktopManager.toString() : "");
  238.  
  239.     return super.paramString() +
  240.     ",desktopManager=" + desktopManagerString;
  241.     }
  242.  
  243. /////////////////
  244. // Accessibility support
  245. ////////////////
  246.  
  247.     /**
  248.      * Get the AccessibleContext associated with this JComponent
  249.      *
  250.      * @return the AccessibleContext of this JComponent
  251.      */
  252.     public AccessibleContext getAccessibleContext() {
  253.         if (accessibleContext == null) {
  254.             accessibleContext = new AccessibleJDesktopPane();
  255.         }
  256.         return accessibleContext;
  257.     }
  258.  
  259.     /**
  260.      * The class used to obtain the accessible role for this object.
  261.      * <p>
  262.      * <strong>Warning:</strong>
  263.      * Serialized objects of this class will not be compatible with
  264.      * future Swing releases.  The current serialization support is appropriate
  265.      * for short term storage or RMI between applications running the same
  266.      * version of Swing.  A future release of Swing will provide support for
  267.      * long term persistence.
  268.      */
  269.     protected class AccessibleJDesktopPane extends AccessibleJComponent {
  270.  
  271.         /**
  272.          * Get the role of this object.
  273.          *
  274.          * @return an instance of AccessibleRole describing the role of the 
  275.          * object
  276.          * @see AccessibleRole
  277.          */
  278.         public AccessibleRole getAccessibleRole() {
  279.             return AccessibleRole.DESKTOP_PANE;
  280.         }
  281.     }
  282. }
  283.  
  284.